//index.js
//获取应用实例
var app = getApp()
Page({

  data: {
    motto: 'Hello World',
    userInfo: {}
  },

  /**
    * 登录
    */
  _doLogin: function () {
    //调用登录接口
    wx.login({
      success: (e) => {
        //微信登录态
      //  app.globalData.states.wxLogin = true;
        let code = e.code;
        this._requestLogin(code);
      },
    });
  },
  _requestLogin: function (code) {   
    wx.request({
      //url: 'http://10.10.67.77:8180/umfWeChatPlat/html/h5/transactionList.html?storeId=68000150&orderDate=2017-10-20', //仅为示例，并非真实的接口地址
      url:'http://192.168.191.1:8084/fromWX/login.do',
      data: {
        code: code,
        userId: this.data.userId,
        password: this.data.password
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res);
        wx.navigateTo({
          url: '../logs/logs'
        })
      }
    })
  },
  /**
    * 登录按钮提交事件
    */
  onSubmit: function (e) {
    this.setData({
        userId: e.detail.value.userNameInput,
        password: e.detail.value.pwdInput
    });
    this._doLogin();
  }
  /**
     * 登录按钮提交事件
     */
  // onSubmit: function (e) { 
  //   wx.request({
  //     //url: 'http://10.10.67.77:8180/umfWeChatPlat/html/h5/transactionList.html?storeId=68000150&orderDate=2017-10-20', //仅为示例，并非真实的接口地址
  //     url:'http://192.168.191.1:8084/fromWX/login.do',
  //     data: {
  //       userId: e.detail.value.userNameInput,
  //       password: e.detail.value.pwdInput
  //     },
  //     header: {
  //       'content-type': 'application/json' // 默认值
  //     },
  //     success: function (res) {
  //       console.log(res);
  //       wx.navigateTo({
  //         url: '../logs/logs'
  //       })
  //     }
  //   })
  // }
})
